package com.jmz.apt.api.dao;

import com.jmz.apt.api.Provider.AdminUserProvider;
import com.jmz.apt.api.Provider.TimeTygpGroupProvider;
import com.jmz.apt.api.entity.dbEntity.JmzAdminRole;
import com.jmz.apt.api.entity.dbEntity.JmzAdminUser;
import com.jmz.apt.api.entity.dbEntity.TimeTygpGroup;
import com.jmz.apt.api.message.request.Condition;
import com.jmz.apt.api.message.request.Query;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.springframework.dao.DataAccessException;

import java.util.List;

/**
 * Created by fanglexue on 2019/10/23.
 */

@Mapper
public interface TygpGroupDao {

    @SelectProvider(type = TimeTygpGroupProvider.class, method="select")
    public List<TimeTygpGroup> findGroups(String columns, List<Condition> condition, Query query);

    @SelectProvider(type = TimeTygpGroupProvider.class, method="getCount")
    public Integer count(List<Condition> condition);

    @SelectProvider(type = TimeTygpGroupProvider.class, method="insert")
    public Integer saveGroup(TimeTygpGroup timeTygpGroup) throws DataAccessException;

    @UpdateProvider(type = TimeTygpGroupProvider.class, method="update")
    public Boolean updateUpdateGroup(TimeTygpGroup timeTygpGroup) throws DataAccessException;

    @SelectProvider(type = TimeTygpGroupProvider.class, method="selectOne")
    public TimeTygpGroup findGroupOne(TimeTygpGroup timeTygpGroup);


    /**
     * Find Time template group information with the given id;
     * @param groupId
     * @return
     */
    @Select("SELECT * FROM time_tygp_group  WHERE id = #{id}")
    @Results(
            {
                    @Result(id = true, column = "id", property = "id"),
                    @Result(column = "name", property = "name"),
                    @Result(column = "desc", property = "desc"),
                    @Result(column = "id", property = "ttgItems", many = @Many(select = "com.jmz.apt.api.dao.TygpDao.findTygpsJoinByGroupId", fetchType = FetchType.LAZY)),
            }
    )
    public TimeTygpGroup findTimeGroupInfo(Integer groupId);

}
